package com.situ.stl.fore;

import com.situ.stl.entity.Course;
import com.situ.stl.entity.Result;
import com.situ.stl.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/** 
 * Controller层 - 课程
 */
@RestController("/foreCourseController")
@RequestMapping( value = "/fore/course")
public class CourseController {

    /** 
     */
    @Autowired 
    private CourseService courseService;

    /** 
     * getAll
     */
    @GetMapping 
    public Result getAll( Integer page, Integer limit, Course course) {
        if ( page == null && limit == null) {
        	return Result.success(courseService.search(course));
        } else {
        	return Result.success(courseService.searchByPage(page, limit, course));
        }
    }

    /** 
     * getById
     */
    @GetMapping( value = "/{id}") 
    public Result getById( @PathVariable( value = "id") Integer id) {
        return Result.success(courseService.getById(id));
    }

}